const webpack = require('webpack');
const { merge } = require('webpack-merge');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSS = require('optimize-css-assets-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const base = require('./webpack.base.js');

module.exports = merge(base, {
  mode: 'none',
  devtool: false,
  optimization: {
    minimizer: [
      // 压缩优化代码
      new TerserJSPlugin({
        // parallel: 4,
        exclude: /\/node_modules\//,
        include: /\.min\.js$/,
      }),
      new OptimizeCSS({}), // 压缩css表
    ],
    splitChunks: {
      // 多页面应用
      cacheGroups: {
        // common: {
        //   chunks: 'initial',
        //   minSize: 0,
        //   minChunks: 2,
        // },
        // vendor: {
        //   chunks: 'initial',
        //   test: /node_modules/,
        //   minSize: 0,
        //   minChunks: 2, // 最少被两个文件引用
        //   priority: 2, // 优先级
        // },
        styles: {
          // 创建styles样式表的缓存组
          name: 'styles',
          test: /\.(css|less)$/,
          chunks: 'all',
          // minSize: 1,
          // minChunks: 1,
          // priority: 30,
          enforce: true,
        },
      },
    },
  },
  plugins: [
  ],
});
